<template>
  <div class="app-container">
    <div class="head-container">
      <div style="display: flex;">
        <!-- 搜索 -->
        <label class="el-form-item-label">结束排</label>
        <el-input v-model.trim="query.port" clearable placeholder="结束排" style="width: 185px;" class="filter-item" />
        <label class="el-form-item-label">ip</label>
        <el-input v-model.trim="query.ip" clearable placeholder="ip" style="width: 185px;" class="filter-item" />
        <label class="el-form-item-label">错误码</label>
        <el-input v-model.trim="query.errorCode" clearable placeholder="错误码" style="width: 185px;" class="filter-item" />
        <label class="el-form-item-label">错误信息</label>
        <el-input v-model.trim="query.errorMsg" clearable placeholder="错误信息" style="width: 185px;" class="filter-item" />
        <div style="margin-left: 5px;">
          <el-button type="success" size="mini" class="filter-item" icon="el-icon-search">搜索</el-button>
          <el-button type="warning" size="mini" class="filter-item" icon="el-icon-refresh-right">重置</el-button>
        </div>
      </div>
      <!-- 列表渲染 -->
      <el-table ref="table" v-loading="loading" :data="list" size="small" style="width: 100%;">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="id" label="ID" />
        <el-table-column prop="port" label="结束排" />
        <el-table-column prop="ip" label="ip" />
        <el-table-column prop="errorCode" label="错误码" />
        <el-table-column prop="errorMsg" label="错误信息" />
      </el-table>
      <!-- 分页 -->
      <el-pagination
        :page-size.sync="query.page.size"
        :total="total"
        :current-page.sync="query.page.current"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChangeHandler($event)"
        @current-change="pageChangeHandler"
      />
    </div>
  </div>
</template>

<script>
import { getPlcLogListAPI } from '@/api/work/wcsMission'
export default {
  name: 'PlcMistakeLog',
  data() {
    return {
      query: {
        wmsTaskNo: '',
        isWrapped: '',
        isStrapping: '',
        status: '',
        page: {
          current: 1,
          size: 20
        }
      },
      total: 0,
      loading: false,
      list: [
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 1,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 2,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 3,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 4,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 5,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 8,
        //   errorMsg: '超高2',
        //   id: 6,
        //   port: '1026CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 7,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 8,
        //   errorMsg: '超高2',
        //   id: 8,
        //   port: '1026CV'
        // },
        // {
        //   errorCode: 4,
        //   errorMsg: '升降变频器报警',
        //   id: 9,
        //   port: '1001CV'
        // },
        // {
        //   errorCode: 8,
        //   errorMsg: '超高2',
        //   id: 10,
        //   port: '1026CV'
        // }
      ]
    }
  },
  mounted() {
    this.toQuery()
  },
  methods: {
    toQuery() {
      this.query.page.current = 1
      this.getTable()
    },
    async getTable() {
      try {
        this.loading = true
        const res = await getPlcLogListAPI(this.query)
        if (res.result === 'OK') {
          this.list = res.data.records
          this.total = res.data.total
        }
      } finally {
        this.loading = false
      }
    },
    sizeChangeHandler(e) {
      this.query.page.size = e
      this.query.page.current = 1
      this.getTable()
    },
    pageChangeHandler(e) {
      this.query.page.current = e
      this.getTable()
    }
  }
}
</script>

<style scoped lang="scss">
</style>
